<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>列表</title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="../../static/css/admin.css" media="all" />
</head>

<body>
  <div id="TMM_app">
    <div class="layui-fluid">
      <div class="layui-card">
        <div class="layui-tab layui-tab-brief tmm-table-tab" lay-filter="component-tabs-brief">
          <ul class="layui-tab-title" id="ulStatus">
            <li status="0" id="order0" class="layui-this"></li>
            <li status="1" id="order1"></li>
            <li status="2" id="order2"></li>
            <li status="3" id="order3"></li>
            <li status="4" id="order4"></li>
            <li status="10" id="order10"></li>
          </ul>
          <div class="layui-tab-content">
          </div>
        </div>
        <div class="layui-form layui-card-header tmm-admin-card-header-auto tmm-filter-form">
          <input type="hidden" id="statusInput"/>
          <input type="hidden" id="trackingNumber"/>
          <input type="hidden" id="logistics_company"/>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">订单编号</label>
              <div class="layui-input-inline">
                <input type="text" name="order_sn" id="order_sn" placeholder="订单编号" autocomplete="off" class="layui-input" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">用户id</label>
              <div class="layui-input-inline">
                <input type="text" name="uid" id="uid" placeholder="用户id" autocomplete="off" class="layui-input" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">订单更新时间</label>
              <div class="layui-input-inline">
                <input type="text" name="time" id="time" placeholder="请选择时间" autocomplete="off" class="layui-input" />
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label" style="width: 70px;">订单状态</label>
              <div class="layui-input-inline">
                <select name="status" id="status">
                  <option value="0">全部</option>
                  <c:forEach items="${statusList}" var="statusInfo">
                    <option value="${statusInfo.status}">${statusInfo.name}</option>
                  </c:forEach>
                </select>
              </div>
            </div>

            <div class="layui-inline">
              <button class="layui-btn tmm-admin-btn-list" lay-submit="" id="query" lay-filter="LAY-app-contlist-search">
                搜索
              </button>
            </div>
          </div>
        </div>
        <div class="layui-card-body">

          <table id="tmm-doctors-table" lay-filter="tmm-doctors" class="layui-table"></table>
          <script type="text/html" id="tmm-admin-app-cont-tagsbar">
              <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查看订单</a>
              {{#  if(d.status==1){ }}
                  <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="delivery">发货</a>
              {{#  } else { }}
              {{#  } }}
              {{#  if(d.status==1 || d.status==2 ){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="refundMoney">退款</a>
              {{#  } else { }}
              {{#  } }}

          </script>
        </div>
      </div>
    </div>
  </div>

  <script src="../../static/lib/layui/layui.js"></script>
  <script>
    layui
      .config({
        base: "../../static/js/"
      })
      .extend({
        index: "index"
      })
      .use(["index", "table", "laydate"], function () {
        var $ = layui.$,
          admin = layui.admin,
          view = layui.view,
          table = layui.table,
          form = layui.form;
          laydate = layui.laydate,

          laydate.render({
            elem: "#time",
            type:'datetime'
          });



        $(".layui-btn.tmm-admin-btn-tags").on("click", function () {
          var type = $(this).data("type");
          active[type] ? active[type].call(this) : "";
        });

        table.render({
          elem: "#tmm-doctors-table",
          skin: 'nob',
          size: 'lg',
          height: 'full-280',
          even: true,
          page: true,
          limit: 10,
          limits: [10, 20, 50],
          url: "${path}/order/getList",
          where:{
              order_sn:$("#order_sn").val(),
              time:$("#time").val(),
              status:$("#status").val(),
              uid:$("#uid").val()
          },
          cols: [[
              {field:'order_sn', title: '订单编号'},
              {field:'create_time', title: '下单时间',width:"14%",templet:function (d) {
                  if(d.create_time!=null && d.create_time!=''){
                      return d.create_time.substring(0,19)
                  }
                  return "无";
              }},
              {field:'uid', title: '购买用户id'},
              {field:'goods_name', title: '产品名称'},
              {field:'goods_inner_price', title: '产品金额'},
              {field:'goods_units', title: '规格'},
              {field:'statusName', title: '订单状态'},
              {field:'order_sn', title: '操作',toolbar:"#tmm-admin-app-cont-tagsbar"},
            ]],
          done: function(res, curr, count){
              $(".layui-table-main  tr").each(function (index ,val) {
                  $($(".layui-table-fixed .layui-table-body tbody tr")[index]).height($(val).height());
              });
          },
          text:{none:"暂无数据"},
        });
        table.on("tool(tmm-doctors)", function (t) {
          var n = t.data;
          switch (t.event){
              case 'detail':
                  window.location.href = "${path}/order/detail?order_sn="+n.order_sn;
                  return;
              case 'delivery':
                  layer.open({
                    type: 1,
                    shade: 0.8,
                    offset: 'auto',
                    shadeClose: true,//点击外围关闭弹窗
                    scrollbar: false,//不现实滚动条
                    title: "添加快递信息", //不显示标题
                    area: ['30%', '30%'],
                    content: "<div class='layui-layer-content' style='top: 20px;'>" +
                            "<div style='display:flex;margin-left: 50px;line-height: 30px;'>" +
                            "<div class=\"form-group\"><label class=\"font-normal\">收货人：</label>"+n.name+"</div>" +
                            "</div>" +
                            "<div style='display:flex;margin-left: 50px;line-height: 30px;'>" +
                            "<div class=\"form-group\"><label class=\"font-normal\">联系电话：</label>"+n.phone+"</div>" +
                            "</div>" +
                            "<div style='display:flex;margin-left: 50px;line-height: 30px;'>" +
                            "<div class=\"form-group\"><label class=\"font-normal\">收获地址：</label>"+n.address+"</div>" +
                            "</div>" +
                            "<div style='display:flex;margin-left: 50px;line-height: 30px;'>" +
                            "<label class=\"font-normal\">快递单号：</label><input type='text' id='l_id' style='width: 70%;'/>" +
                            "</div>" +
                            "<div style='display:flex;margin-left: 50px;line-height: 30px;'>" +
                            "<label class=\"font-normal\">快递公司：</label><input type='text' id='logistics_company1' style='width: 70%;'/>" +
                            "</div>" +
                            "</div>",
                    btn:['确认', "取消"],
                    btnAlign:'c',
                    yes: function (index,layero) {
                      if($("#l_id").val()==""){
                        layer.alert("请填写快递单号",{icon:2});
                        return;
                      }
                      if($("#logistics_company1").val()==""){
                        layer.alert("请填写快递公司",{icon:2});
                        return;
                      }
                      $("#trackingNumber").val($("#l_id").val());
                      $("#logistics_company").val($("#logistics_company1").val());
                      layer.close(index);
                      layer.confirm("再次确认快递单收件信息确认无误", function (e) {
                        if($("#trackingNumber").val()==""){
                          layer.alert("请填写快递信息",{icon:2});
                        }
                        var index = layer.load(2);
                        $.ajax({
                          type:"post",
                          url:"${path}/order/editOrderStatus",
                          dataType:"json",
                          data:{order_sn:n.order_sn,status:2,trackingNumber:$("#trackingNumber").val(),logistics_company:$("#logistics_company").val(),address:n.address},
                          success:function(data){
                            layer.close(index);
                            if(data.code ==0){
                              layer.alert(data.msg,{icon:1}, function(){
                                location.reload();
                              });
                            }else{
                              layer.alert(data.msg,{icon:2});
                            }
                          },
                          error:function (data) {
                            layer.close(index);
                          }
                        });
                        return false;
                      })
                    }
                    // layer.alert(data.msg,{icon:1}, function(){
                    //   location.reload();
                    // });
                  });

                  return;
            case 'refundMoney':
              layer.confirm("当前订单【"+n.order_sn+"】是否退款", function (e) {
                var index = layer.load(2);
                $.ajax({
                  type:"post",
                  url:"${path}/order/backMoney",
                  dataType:"json",
                  data:{id:n.id,order_sn:n.order_sn,type:1},
                  success:function(data){
                    layer.close(index);
                    if(data.code ==0){
                      layer.alert(data.msg,{icon:1}, function(){
                        location.reload();
                      });
                    }else{
                      layer.alert(data.msg,{icon:2});
                    }
                  },
                  error:function (data) {
                    layer.close(index);
                  }
                });
                return false;
              })
              return;
          }
        });
        //查询
        $('#query').on('click', function(){
            table.reload('tmm-doctors-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    order_sn:$("#order_sn").val(),
                    time:$("#time").val(),
                    status:$("#status").val(),
                    uid:$("#uid").val()
                }
            }, 'data');
        });
      });
  </script>
</body>

</html>